package org.lxy.utils;

import cn.hutool.core.bean.BeanUtil;
import org.lxy.service.*;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author 卢心怡
 */
@Component
public class CoreUtils implements ApplicationContextAware {

    public static Map toMap(Object object){
        return BeanUtil.beanToMap(object,true,true);
    }

    public static ApplicationContext applicationContext;

    public static GoodsTypeService goodsTypeService;

    public static InfomationService infomationService;

    public static PointsLogService pointsLogService;

    public static RecordLogService recordLogService;

    public static RecycleGoodsService recycleGoodsService;

    public static RecyclePointService recyclePointService;

    public static UserInfoService userInfoService;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        CoreUtils.applicationContext=applicationContext;
        CoreUtils.goodsTypeService=applicationContext.getBean(GoodsTypeService.class);
        CoreUtils.infomationService=applicationContext.getBean(InfomationService.class);
        CoreUtils.pointsLogService=applicationContext.getBean(PointsLogService.class);
        CoreUtils.recordLogService=applicationContext.getBean(RecordLogService.class);
        CoreUtils.recycleGoodsService=applicationContext.getBean(RecycleGoodsService.class);
        CoreUtils.recyclePointService=applicationContext.getBean(RecyclePointService.class);
        CoreUtils.userInfoService=applicationContext.getBean(UserInfoService.class);
    }


}
